home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / misc / AWNP_2-39.lha / AWNP / AWNP-Docs / Demos / dictionary.rx < prev    next >
Text File  |  2000-02-04  |  9KB  |  351 lines

  1. /*Online dictionary Vers 1.1
  2. Run from the shell or workbench
  3. 'rx dictionary.rx word_to_find' to see definition
  4. 'rx dictionary.rx ' to open GUI
  5. This script uses the Meriam Webster site to look up definitions.
  6. www.m-w.com
  7. */
  8.  
  9. trace('E')
  10.  
  11. if ~show('L','rexxsupport.library') then
  12. if ~addlib('rexxsupport.library',0,-30,0) then
  13. exit(20)
  14. call pragma('priority',1)
  15. nl='a'x
  16. /*call setupbubble()*/
  17. delaybub=0
  18. parse arg w .
  19. if w~='' then do
  20. shell=1
  21. call trans()
  22. say w
  23. say txt
  24. exit
  25. end
  26.  
  27.  
  28. call setdefaults()
  29. call buildgui()
  30.  
  31. do while ~eof(ca)
  32. if delaybub>0 then do
  33. delaybub=delaybub-1
  34. if delaybub=0 then do
  35. bubleon=newbub
  36. call topipe('bubble top 'bubx 'left 'buby 'gt "'help.newbub'"')
  37. end
  38. end
  39.   call topipe('tick 50')
  40.   in= readln(ca)
  41.   parse var in in1 in2 in3 in4 in5 .
  42.   if (in1='help' & helpon~=0 ) then do
  43. call bubble(in2)
  44. end
  45.   if in1='active' then call bubble(0)
  46.   if in1='key' then call key()
  47.   if in1='gadget' then call gadget()
  48.   if in1='iconify' then call iconify()
  49.   if in1='menu' then call menu()
  50.   if in1='close' then call windowclosed()
  51. end
  52. exit
  53.  
  54. key:
  55.  
  56. scrpos=topipe('id 'txtgad)
  57. if scrpos=oldpos then scrpos=scrpos-40
  58. if ((in2=77) & (scrpos<oldpos)) then scrpos=topipe('id 'txtgad' scroll' scrpos+80)
  59. if (in2=76) then do
  60. if (scrpos>79) then scrpos=topipe('id 'txtgad' scroll' scrpos-80)
  61. else scrpos=topipe('id 'txtgad' scroll 0' )
  62. end
  63. return
  64.  
  65. gadget:
  66. call bubble(0)
  67. if in2=wordgad then do
  68.   parse var in . . w .
  69.   call trans()
  70.   call topipe('id 'txtgad' scroll -1 gt "*n-----*n'in3'*n*n"')
  71.   call writeln(ca,'id 'txtgad' scroll -1 bd gt "'length(txt)+1'"')
  72.   newpos=topipe(txt)
  73.   call topipe('id 'txtgad' scroll 'oldpos)
  74.   oldpos=newpos
  75. end
  76. if in2=quitgad then exit
  77. if in2=cleargad then oldpos=topipe('id 'txtgad' gt ""')
  78. if in2=savegad then do
  79.   call writeln(ca,'id 'filegad' s 1 save 1 fn "'filename'"')
  80.   parse value readln(ca) with res1 '"' res2 '"'
  81.   if (res1>0) then do
  82.     filename=res2
  83.     call writeln(ca,'id 'txtgad' read')
  84.     len=readln(ca)
  85.     data=readch(ca,len)
  86.     if( open(out,res2,'W')) then do
  87.       call   writech(out,data)
  88.       call   close(out)
  89.     end
  90.   end
  91. end
  92. return
  93.  
  94. windowclosed:
  95. /*call setenv()*/
  96. exit
  97. return
  98.  
  99. setdefaults:
  100. parse source . . called .
  101. oldpos=0
  102. filename=''
  103. scrpos=''
  104. envname='onlinedictionary'
  105. call getenv()
  106. abouttx='Online Dictionary*nVers 1.1*nAuthor William Parker*nGUI by AWNPipe:'
  107. return
  108.  
  109. buildgui:
  110. help.1=' Enter word to look up '
  111. help.2=' This area displays the retreived definitions. It is read only *n but you may drag and copy the results to the clipboard. *n The cursor keys can be used to scroll the information.'
  112. help.4=' Save retreived definitions to a file '
  113. help.5=' Remove all retreived definitions '
  114. help.6=' Quit the dictionary '
  115. call open(ca,"awnpipe:dict/xc")
  116. call topipe(' ps awebb "Online Dictionary" sk v defg ig h state m a 'window' ii "'called'"' )
  117. call topipe(' label gt "Word: " ua')
  118. wordgad=topipe('string chl lj')
  119. txtgad=topipe('textfield ro arrows')
  120. call topipe(' layout weih 0')
  121. savegad=topipe('button gt "Save Log"')
  122. cleargad=topipe('button gt "Clear Log"')
  123. quitgad=topipe('button gt "Quit"')
  124. call topipe(' layoutend')
  125. filegad=topipe('getfile save ua')
  126. men0gad= topipe('Menu gt "Project|Window|$@SSnapshot|$@UUnsnapshot|@AAbout|@H^&Bubble Help|-|@QQuit"')
  127. call pragma('W','N')
  128. if (showlist('A','MIAMI')|(showlist('P','MIAMI.1'))) then do
  129.   men1gad= topipe('Menu gt "Miami|Online|Offline|Status|Hide GUI|Show GUI|SSL Version 2|$On|$Off|-|Quit Miami"')
  130. end
  131. call pragma('W')
  132. call topipe("open")
  133. return
  134.  
  135. topipe:
  136. /* this routine does error checking on lines written to pipe.*/
  137. /*get line to output*/
  138. parse arg out
  139. /* write to the pipe*/
  140. call writeln(ca,out)
  141. /*get responce and parse it.*/
  142. res=readln(ca)
  143. parse var res res1 res2 res3
  144. /* if all is ok return the second part of the responce (usualy the GID)*/
  145. if res1='ok' then return(res2)
  146. /* something went wrong, we notify the user then exit */
  147. /*show problem line and responce (reponce may be just a blank line)*/
  148. say 'error from: 'out
  149. say '  responce: ' in
  150. exit
  151.  
  152. trans:
  153. if testtcp() then return
  154. if shell~=1 then do
  155. call topipe('id 'wordgad' dis 1 ref')
  156. call topipe('id 0 s 8 gt " Connecting ..."')
  157. end
  158. w=translate(w,' ','+')
  159. t1='book=Dictionary&va='w
  160. t2=length(t1)
  161. t2='Content-Length: 't2
  162. call open(net,'tcp:www.m-w.com/80')
  163. if shell~=1 then call topipe('id 0 s 8 gt " Getting definition ..."')
  164. call writeln(net,"POST /cgi-bin/dictionary HTTP/1.0")
  165. call writeln(net,"User-Agent: MSIE/4.0; (Spoofed by billybobsdictthing (1.0 beta))")
  166. call writeln(net,"Accept: */*;q=1")
  167. call writeln(net,"Host: www.m-w.com")
  168. call writeln(net,t2)
  169. call writeln(net,"Content-Type: application/x-www-form-urlencoded")
  170. call writeln(net,"")
  171. call writeln(net,t1)
  172. call writeln(net,"")
  173. def=''
  174. do while ~eof(net)
  175.   if length(def)< 54000 then def=def||readch(net,10000)
  176. end
  177. parse var def 'Main Entry:'. '0a'x d1 '<center>'
  178. do while index(d1,'<br>')>0
  179.   parse var d1 d2 '<br>' d3
  180.   d1=d2||'0a'x||d3
  181. end
  182. do while index(d1,'<')>0
  183.   parse var d1 d2 '<' . '>' d3
  184.   d1=d2||d3
  185. end
  186. call open(fh,'awnpipe:dec/u/f','W')
  187. call writech(fh,d1)
  188. call close(fh)
  189. if shell~=1 then call topipe('id 0 s 8 gt " Parsing result ..."')
  190. call open(fh,'awnpipe:dec','R')
  191. sel=readch(fh,64000)
  192. call close(fh)
  193. d1='0a'x'Etymology:'
  194. parse var sel t1 (d1) . 'Date:' . '0a'x t2
  195. sel=t1||t2
  196. wrap=75
  197. txt=''
  198. do while sel~=''
  199.   parse var sel line '0a'x sel
  200.   if length(line)<wrap then txt=txt||line||'0a'x
  201.   else do
  202.     wrapc=wrap
  203.     do while line~=''
  204.       parse var line wrd line
  205.       wrdl=length(wrd)
  206.       if wrdl <= wrapc then do
  207.         txt=txt||wrd' '
  208.         wrapc=wrapc-wrdl-1
  209.       end
  210.       else do
  211.         txt=txt||'0a'x||wrd' '
  212.         wrapc=wrap-wrdl-1
  213.         if wrapc<=0 then do
  214.           wrapc=wrap
  215.           txt=txt||'0a'x
  216.         end
  217.       end
  218.     end
  219.     txt=txt||'0a'x
  220.   end
  221. end
  222. if txt='' then txt= 'not found'
  223. call close(net)
  224. if shell~=1 then do
  225. call topipe('id 'wordgad' dis 0 ref')
  226. call topipe('id 0 s 8 gt " Online Dictionary"')
  227. end
  228.  
  229. return
  230.  
  231. showtx:
  232. call open(ptx,'awnpipe:tbtxt/xc')
  233. call writeln(ptx,'db dg Information q cg m a so si ')
  234. call writeln(ptx,'label gt "'arg(2)'"')
  235. call writeln(ptx,'open')
  236. if arg(1)=0 then call writeln(ptx,'m')
  237. else call writeln(ptx,'tick 'arg(1))
  238. call close(ptx)
  239. return(0)
  240.  
  241. menu:
  242. if in2=1 then do
  243.   if in3=5 then do
  244.     if in4=0 then do
  245.       address command "echo yes >ENV:Miami/SSLVERSION2"
  246.       call showtx(200,' Miami SSL Version 2 on ')
  247.     end
  248.     else do
  249.       address command "echo no >ENV:Miami/SSLVERSION2"
  250.       call showtx(200,' Miami SSL Version 2 off ')
  251.     end
  252.     return()
  253.   end
  254.   if ~show('P','MIAMI.1') then do
  255.     if in3=1 | in3=1 | in3=6 then do
  256.       call showtx(200,' Miami is not running ')
  257.       return()
  258.     end
  259.     address command 'Run >NIL: Miami:Miami '
  260.     do 5 while ~show('P','MIAMI.1')
  261.       address command 'waitforport MIAMI.1'
  262.     end
  263.     if rc=5 then return()
  264.   end
  265.   if in3=1 | in3=6 then address MIAMI.1 'OFFLINE'
  266.   if in3=7 then address MIAMI.1 'QUIT'
  267.   if in3=0  then address MIAMI.1 'ONLINE'
  268.   if in3=3 then address MIAMI.1 'HIDE'
  269.   if in3=4 then address MIAMI.1 'SHOW'
  270.   if in3=2 | in1 =0 | in1=11 then do
  271.     address MIAMI.1 'ISONLINE'
  272.     if rc then call showtx(200,' Miami is online ')
  273.     else call showtx(200,' Miami is offline ')
  274.   end
  275. end
  276. if in2=0 then do
  277. if in3=0 then do
  278. if in4=0 then call setenvarc()
  279. if in4=1 then call unsetenvarc()
  280. end
  281. if in3=1 then call showtx(500,abouttx)
  282. if in3=2 then do
  283. helpon=in5
  284. if helpon=0 then call bubble(0)
  285. end
  286. if in3=4 then  exit
  287. end
  288. return()
  289.  
  290. iconify:
  291. if in2=1 then call topipe('id 0 s 32')
  292. else call topipe('id 0 s 64')
  293. return
  294.  
  295. getenv:
  296. if(open(env,'env:'envname,'R')) then do
  297. windows=readln(env)
  298. filename=readln(env)
  299. call close(env)
  300. parse var windows wl wt ww wh .
  301. window= 'top' wt 'left' wl 'width' ww 'height' wh
  302. end
  303. else window='tl width 400 height 200'
  304. return
  305.  
  306. setenv:
  307. call writeln(ca,'id 0 read')
  308. windowr=readln(ca)
  309. parse var windowr wl wt ww wh .
  310. if (datatype(wt,N) &datatype(wl,N) &datatype(ww,N) & datatype(wh,N) ) then do
  311. call open(env,'env:'envname,'W')
  312. call writeln(env,windowr)
  313. call writeln(env,filename)
  314. call close(env)
  315. end
  316. return(0)
  317.  
  318. setenvarc:
  319. call setenv()
  320. address command 'copy env:'envname' envarc:'envname '>nil:'
  321. return
  322.  
  323. unsetenvarc:
  324. call setenv()
  325. if exists('envarc:'envname) then delete('envarc:'envname)
  326. if exists('env:'envname) then delete('env:'envname)
  327. return
  328.  
  329. testtcp:
  330. call pragma('W','N')
  331. if ~showlist(H,'TCP') then do
  332. showtx(0,'Can not find TCP device*nYou must be online*nto use dictionary')
  333. call pragma('W')
  334. return(1)
  335. end
  336. call pragma('W')
  337. return(0)
  338.  
  339. bubble:
  340. newbub=arg(1)
  341. if newbub=-1 then newbub=0
  342. if (bubbleon=newbub) then return()
  343. if bubbleon~=0 then call  topipe('bubble')
  344. if newbub=0 then delaybub=0
  345. else do
  346. bubx=in3
  347. buby=in4
  348. delaybub=3
  349. end
  350. return
  351.